﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace FYPDemo
{
    public partial class ChangePassword : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnChange_Click(object sender, EventArgs e)
        {
            int result2 = 0;
            string oldPw = "";
            string newPw = "";
            string ConfirmPw = "";
            string email = "";
            string name = Session["username"].ToString();

            oldPw = txtOldPw.Text;
            newPw = txtNewPw.Text;
            ConfirmPw = txtConfirmNewPw.Text;

            DataTable dt = Member.verifyOldPassword(name, oldPw);

            if (dt.Rows.Count > 0)
            {

                if (dt.Rows[0][0].ToString() == name)
                {
                    email = dt.Rows[0][1].ToString();
                    result2 = Member.updatePassword(name, newPw);

                    if (result2 > 0)
                    {
                        string subject = "Your Password successfully Changed";
                        string body = "Dear Mr/Mrs " + name + ", <br /><br />  Kindly inform you that your password has been reset: ";
                        body = body + "Please log in using the information below! <br/><br/>";
                        body = body + "<b><span style=\"color:slateblue\">User Name: </span></b>" + name + "<br />" + "<br /> <br />";
                        body = body + "<b><span style=\"color:slateblue\">New Password: </span></b>" + newPw + "<br />" + "<br /> <br />";
                        body = body + "Thank you." + "<br />" + "<br />" + "<span style=\"font-style:italic; color:gray; font-size:11pt\"></span>";

                        SendMail.SendEmail(email, subject, body);
                    }

                    else
                    {
                        //x success update
                    }
                }

                else
                {
                    MessageBox.Show("The password is incorrect.");
                }
            }


        }
    }
}